using ServoDrivesLib.Model;
using ServoDrivesLibAbstract;

namespace ServoDrivesLib.Controls;

public class CardControlManager
{
    protected internal readonly Dictionary<string, IControlCard> _buffer;

    public static CardControlManager Instance { get; } = new CardControlManager();

    public CardControlManager()
    {
        _buffer = new Dictionary<string, IControlCard>();
    }

    public virtual void Register(string cardName, IControlCard cardControl)
    {
        ArgumentNullException.ThrowIfNull(cardName);
        if (!_buffer.ContainsKey(cardName))
        {
            _buffer.Add(cardName, cardControl);
        }
    }
    public virtual IControlCard? Get(string cardName)
    {
        _buffer.TryGetValue(cardName, out var cardControl);
        return cardControl;
    }
}
